﻿using UnityEngine;
using System.Collections;

public class BoatAnimationController : MonoBehaviour {
    public GameObject graphs;
    public GameObject[] graph_objects;
    public bool ready =true;
    public Animator animator;
    public bool fishing;
    public string nome;
    static int[] fishhashs = { Animator.StringToHash("Base.fishing"), Animator.StringToHash("Base.fishingOut") };
    

    public void setFishing(bool fishing)
    {
       animator.SetBool("fishing", fishing);
       this.fishing = fishing;
      // ready = false;
    }
    public const int N = 0,
        NE = 1,
        E = 2,
        SE = 3,
        S = 4,
        SW = 5,
        W = 6,
        NW = 7;
    public float angle;
    public int angleIndex;

	// Use this for initialization
	void Start () {
	}

    void explode()
    {
        ready = false;
        animator.SetBool("explode", true);
    }

	// Update is called once per frame
	void Update () {

        graphs.transform.rotation = Quaternion.identity;
        angle = Vector3.Angle(new Vector3(0, 0, 1), transform.forward.normalized);
        if (transform.forward.x < 0)
            angle = 360 - angle;
        angleIndex = ((int) Mathf.Floor((angle + 25.0f) / 45.0f)) % 8;
        
        for (int i = 0; i < graph_objects.Length; i++)
        {
            graph_objects[i].SetActive(i == angleIndex);
        }
        int nh = animator.GetCurrentAnimatorStateInfo(0).nameHash;
        ready = true;
        foreach (int h in fishhashs)
        {
            if (h == nh)
            {
                ready = false;
                break;
            }
        }
	}
}
